package com.lt.flashcard.model.entity;

import java.util.ArrayList;
import java.util.Date;
import java.util.List;

import org.bson.types.ObjectId;

import com.google.code.morphia.annotations.Entity;
import com.google.code.morphia.annotations.Id;
import com.google.code.morphia.annotations.Reference;

/**
 * Store information when user start a journey
 * @author ocsen
 *
 */
@Entity("journeyhistory")
public class JourneyHistory {

	@Id
	private ObjectId id;
	private Long userid;
	@Reference
	private Journey journey;
	private Date started = new Date();
	private Date finished;
	private int status = STATUS_NEW;
	public static final int STATUS_NEW = 0;
	public static final int STATUS_STARTED = 1;
	public static final int STATUS_FINISHED = 2;
	/**
	 * Current gained coin of this user
	 */
	private int currentCoin = 0;
	/**
	 * The time that user got the item
	 */
	private List<Date> itemHistory = new ArrayList<Date>();
	
	public ObjectId getId() {
		return id;
	}
	
	public void setId(ObjectId id) {
		this.id = id;
	}
	
	public Long getUserid() {
		return userid;
	}
	
	public void setUserid(Long userid) {
		this.userid = userid;
	}
	
	public Journey getJourney() {
		return journey;
	}
	
	public void setJourney(Journey journey) {
		this.journey = journey;
	}
	
	public Date getStarted() {
		return started;
	}
	
	public void setStarted(Date started) {
		this.started = started;
	}
	
	public Date getFinished() {
		return finished;
	}
	
	public void setFinished(Date finished) {
		this.finished = finished;
	}
	
	public int getStatus() {
		return status;
	}
	
	public void setStatus(int status) {
		this.status = status;
	}
	
	public int getCurrentCoin() {
		return currentCoin;
	}

	public void setCurrentCoin(int currentCoin) {
		this.currentCoin = currentCoin;
	}
	
	public boolean isNew() {
		return status == STATUS_NEW;
	}
	
	public boolean isStarted() {
		return status == STATUS_STARTED;
	}
	
	public boolean isFinished() {
		return status == STATUS_FINISHED;
	}

	public List<Date> getItemHistory() {
		return itemHistory;
	}

	public void setItemHistory(List<Date> itemHistory) {
		this.itemHistory = itemHistory;
	}
	
	/**
	 * Check to see if user got an item
	 * @param index
	 * @return
	 */
	public boolean gotItem(int index) {
		return index < itemHistory.size();
	}
}
